<?php

class Mageex_RelatedProduct_Block_Adminhtml_RelatedProduct_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
  protected function _prepareForm()
  {
      $form = new Varien_Data_Form();
      
      $fieldset = $form->addFieldset('relatedproduct_form', array('legend'=>Mage::helper('relatedproduct')->__('General')));
      $model = Mage::registry('relatedproduct_data');
      $fieldset->addField('name', 'text', array(
          'label'     => Mage::helper('relatedproduct')->__('Block Name'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'name',
      ));

      $fieldset->addField('status', 'select', array(
          'label'     => Mage::helper('relatedproduct')->__('Status'),
          'name'      => 'status',
		  'required'  => true,
          'values'    => array(
              array(
                  'value'     => 1,
                  'label'     => Mage::helper('relatedproduct')->__('Enabled'),
              ),

              array(
                  'value'     => 2,
                  'label'     => Mage::helper('relatedproduct')->__('Disabled'),
              ),
          ),
      ));
		/**
         * Check is single store mode
         */
		if(Mage::app()->isSingleStoreMode())
        {
            $fieldset->addField('stores', 'hidden', array(
                'name'      => 'stores[]',
                'value'     => Mage::app()->getStore()->getId(),
            ));
        }
        else {
            $fieldset->addField('stores', 'multiselect', array(
                'name'      => 'stores[]',
                'label'     => $this->__('Store View'),
                'title'     => $this->__('Store View'),
                'required'  => true,
                'values'    => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
            ));
        }
		/*
		$fieldset->addField('group_customer', 'multiselect', array(
                'name'      => 'group_customer[]',
                'label'     => Mage::helper('cms')->__('Group Customer'),
                'title'     => Mage::helper('cms')->__('Group Customer'),
                'required'  => true,
                'values'    => Mage::getModel('relatedproduct/customergroup')->getCustomerGroupForForm(),
            ));
		*/
		$fieldset->addField('priority', 'text', array(
          'label'     => Mage::helper('relatedproduct')->__('Priority'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'priority',
      ));	
	  
		$dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
        
		$fieldset->addField('date_start', 'date', array(
            'name'   => 'date_start',
            'label'  => Mage::helper('relatedproduct')->__('Date From'),
            'title'  => Mage::helper('relatedproduct')->__('Date From'),
            'image'  => $this->getSkinUrl('images/grid-cal.gif'),
            'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
            'format'       => $dateFormatIso
        ));
		$fieldset->addField('date_expire', 'date', array(
            'name'   => 'date_expire',
            'label'  => Mage::helper('relatedproduct')->__('Date To'),
            'title'  => Mage::helper('relatedproduct')->__('Date To'),
            'image'  => $this->getSkinUrl('images/grid-cal.gif'),
            'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
            'format'       => $dateFormatIso
        ));
		$fieldset->addField('position', 'select', array(
          'label'     => Mage::helper('relatedproduct')->__('Position'),
          'name'      => 'position',
		  'required'  => true,
          'values'    => Mage::helper('relatedproduct')->getBlockIdsToOptionsArray()
      ));
		$this->setForm($form);
      if ( Mage::getSingleton('adminhtml/session')->getRelatedProductData() )
      {
          $form->setValues(Mage::getSingleton('adminhtml/session')->getRelatedProductData());
          Mage::getSingleton('adminhtml/session')->setRelatedProductData(null);
      } elseif ( Mage::registry('relatedproduct_data') ) {
          $form->setValues(Mage::registry('relatedproduct_data')->getData());
      }
	  
      return parent::_prepareForm();
  }
}